package com.personal.common.utils;


/**
 * 处理字符串相关的工具类
 * @ClassName:StringUtils
 * @Description:TODO
 * @author kexl
 * @date 2014-4-18 上午11:18:02 
 *
 */
public class StringUtils {
	/**
	 * 将字符串头尾的逗号（,）去掉
	 * 例如：将,,,1,2,3,,,转换为：1,2,3
	 * @param str
	 * @return
	 */
	public static String trimOne(String str){   
        if(str.startsWith(","))
            return trimOne(new String(new StringBuffer(str).deleteCharAt(0)));
        else if(str.endsWith(","))
            return trimOne(new String(new StringBuffer(str).deleteCharAt(str.length()-1)));
        else
            return str;
	}
	/**
	 * 整数
	 * @param str
	 * @return
	 */
	public static boolean isInteger(String str){ 
		return str.matches("^\\-?[0-9]*$");
	}
	/**
	 * 正整数
	 * @param str
	 * @return
	 */
	public static boolean isPositiveInteger(String str){ 
		return isInteger(str) && Integer.parseInt(str)>0;
	}
	/**
	 * 非负整数（正整数和0）
	 * @param str
	 * @return
	 */
	public static boolean isNonNegativeInteger(String str){ 
		return isInteger(str) && Integer.parseInt(str)>=0;
	}
	/**
	 * 负整数
	 * @param str
	 * @return
	 */
	public static boolean isNegativeInteger(String str){ 
		return isInteger(str) && Integer.parseInt(str)<0;
	}
	public static void main(String[] args) {
		System.out.println(isNegativeInteger("1"));
		System.out.println(isNegativeInteger("0001"));
		System.out.println(isNegativeInteger("0"));
		System.out.println(isNegativeInteger("0000"));
		System.out.println(isNegativeInteger("-1"));
		System.out.println(isNegativeInteger("-0001"));
		System.out.println(isNegativeInteger("-0.0001"));
		System.out.println(isNegativeInteger("1.1"));
	}
}
